package face.pay.web.oem.service.impl;

import face.pay.dao.OemConfigInfoDao;
import face.pay.entity.OemConfigInfo;
import face.pay.entity.OemInfo;
import face.pay.entity.UserInfo;
import face.pay.security.exception.BaseException;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import face.pay.vo.OemUserInfo;
import face.pay.web.oem.service.IOemConfigService;
import face.pay.web.oem.service.IOemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

/**
 * @Auther: zkj
 * @Date: 2019/8/12 13:27
 * @Description:
 */
@Service
public class OemConfigServiceImpl implements IOemConfigService {

    @Autowired
    OemConfigInfoDao configInfoDao;

    @Override
    public void getConfigInfo(UserInfo loginUser, Model model) {

        OemConfigInfo oemConfigInfo = this.configInfoDao.getByOemId(loginUser.getOemId());
        if(oemConfigInfo==null){
            oemConfigInfo =  new OemConfigInfo();
        }
        model.addAttribute("oemConfigInfo",oemConfigInfo);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultMessage modify(OemConfigInfo oemConfigInfo, UserInfo loginUser) {
        Integer id = oemConfigInfo.getId();
        if(id==null || new Integer(0).equals(id)){
            oemConfigInfo.setOemId(loginUser.getOemId());
            oemConfigInfo.setCreatedBy(loginUser.getId());
            this.configInfoDao.insert(oemConfigInfo);
        }else {
            oemConfigInfo.setUpdatedBy(loginUser.getId());
            this.configInfoDao.update(oemConfigInfo);
        }

        return  ResultMessage.createSuccess();
    }
}
